package com.jchen.common.annotation;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @Description
 * @Author jchen
 * @Date 2023/12/25 16:44
 */

@Aspect
@Component
@Slf4j
public class TestAnnotationAop {

    /**
     * 定义切面
     */
    @Pointcut("@annotation(com.jchen.common.annotation.TestAnnotation)")
    public void annotationPointCut() {
    }

    /**
     * 定义方法拦截的规则
     */
    @Around("annotationPointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        //获取请求方法
        Method method = signature.getMethod();
        //获取方法注解
        TestAnnotation action = method.getAnnotation(TestAnnotation.class);
        if("testFeiApi".equals(method.getName())){
            System.out.println("这是测试feignApi");
        }
        return joinPoint.proceed();
    }
}
